// 文本 xml - 读取示例
package main

import (
	"fmt"
	"encoding/xml"
	"io/ioutil"
	"os"
)

type server struct {
	XMLName 	xml.Name 	`xml:"server"`
	ServerName 	string 		`xml:"serverName"`
	ServerIP 	string 		`xml:"serverIP"`
}

type Recurlyservers struct {
	XMLName 	xml.Name 	`xml:"servers"`
	Version 	string 		`xml:"version, attr"`
	Svs     	[]server 	`xml:"server"`
	Description string 		`xml:"", innerxml`
}

func main() {
	// For read access
	file, err := os.Open("servers.xml")
	if err != nil {
		fmt.Printf("error: %v", err)
		return
	}
	defer file.Close()

	data, err := ioutil.ReadAll(file)
	if err != nil {
		fmt.Printf("error: %v", err)
		return
	}

	v := Recurlyservers{}
	err = xml.Unmarshal(data, &v)
	if err != nil {
		fmt.Printf("error: %v", err)
		return
	}

	fmt.Println(v)
}

/*
输出:
{{ servers}  [{{ server} Shanghai_VPN 127.0.0.1} {{ server} Beijing_VPN 127.0.0.2}] }
*/